package com.mars.nacos.domain.service.impl;

import com.mars.nacos.api.dto.request.SmsSendDTO;
import com.mars.nacos.api.dto.response.UserOrderResDTO;
import com.mars.nacos.domain.service.OrderAppService;
import com.mars.nacos.infrastructure.remote.dto.response.UserInfoResDTO;
import com.mars.nacos.infrastructure.remote.facade.UserAppApiRemoteFacade;
import lombok.extern.slf4j.Slf4j;
import org.apache.mf.service.ISmsService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author : kyrie
 * @date : 2022/8/24 09:46
 * #desc    : some description
 */
@Service
@Slf4j
@RefreshScope
public class OrderAppServiceImpl implements OrderAppService {

    @Value("${order.orderNo}")
    private String orderNo;
    @Resource
    private UserAppApiRemoteFacade userAppApiRemoteFacade;

    @Resource
    private ISmsService smsService;

    @Override
    public UserOrderResDTO getOrderNo() {
        log.info("读取配置中心数据为: {}", orderNo);
        UserInfoResDTO userInfoResDTO = userAppApiRemoteFacade.getUserName();
        return UserOrderResDTO.builder().orderNo(orderNo).userName(userInfoResDTO.getNickName()).headUrl(userInfoResDTO.getHeadUrl()).build();
    }

    @Override
    public String send(SmsSendDTO smsSendDTO) {
        smsService.send(smsSendDTO.getPhone(), smsSendDTO.getAreaCode(), smsSendDTO.getSmsTemplateCode(), smsSendDTO.getData());
        return "发送成功！";
    }
}
